/*
 * @Descripttion:   此版本此文件暂无用
 * @version: 
 * @Author: yuanliutech
 * @Date: 2022-11-22 10:08:14
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2023-01-31 15:52:00
 */
const app = getApp()
import {
    showMsg
} from '../../../utils/config.js'
import {
    reqParkList
} from '../../../request/api'
module.exports = Behavior({
    data: {
        showPark: false,
        parkPage: 1,
        parkIsNextPage: true,
    },
    methods: {
        clickShowPark() {
            this.setData({
                showPark: true
            })
        },
        closePark() {
            this.setData({
                showPark: false
            })
        },
        clickParkRadio(e) {
            let type = e.type
            let id = ''
            if (type == 'change') {
                id == e.detail
            } else {
                id = e.target.dataset.id
            }
            let {
                parkList
            } = this.data
            let parkItemInfo = {}
            parkList.forEach(item => {
                if (item.id === id) {
                    parkItemInfo = item
                }
            })
            this.setData({
                parkItemInfo
            })
            this.closePark()
            this.changeParkUpdate()
        },

        async getParkList() {
            let params = {
                userId: app.globalData.userId,
                orgId: app.globalData.orgId ==1?'':app.globalData.orgId,
                roleName: app.globalData.rolename,
            }
            const res = await reqParkList(this.data.parkPage, 20, params)
            if (res.code !== 20000) return showMsg(res.message)
            let {
                rows
            } = res.data
            if (this.data.parkPage === 1) {
                this.setData({
                    parkList: rows,
                    parkIsNextPage: true
                })
            } else if (this.data.parkPage > 1 && rows.length) {
                this.setData({
                    parkList: this.data.parkList.concat(rows),
                    parkIsNextPage: true
                })
            } else if (this.data.parkPage > 1 && !rows.length) {
                showMsg('已经到底啦~')
                this.setData({
                    parkIsNextPage: false
                })
            }
        },
        // 滚动到底部触发
        parkLower() {
            if (!this.data.parkIsNextPage) return
            this.setData({
                parkPage: this.data.parkPage + 1,
            })
            this.getParkList()
        },
    }
})